home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
mfgdemo
/
mfg_model.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-10
|
11KB
|
335 lines
#ifndef lint
static char SccsId[]= "@(#)mfg_model.c V1.10 3/15/95";
#endif
/*------------------------------------------------------------------
| file name -- mfg_model.c
|
| Manufacturing model based on the internal cpu clock - update
| the machine functions.
|
|-----------------------------------------------------------------*/
#include "std.h"
#include "dvstd.h"
#include "dvtools.h"
#include "Tfundecl.h"
#include "mfg_vars.h"
#include "mfg_data.h"
#include "mfg_fundecl.h"
LOCAL INT
temp_factor[NUM_STAMPERS] =
{5, 9, 7}, cycle_timer, current_cycle_time, elapsed_time = 0, current_time = 0, current_cycle_counter; /* (INT)welding_cycle[i] */
LOCAL FLOAT
oven_delta[NUM_OVENS], oven_counter[NUM_OVENS];
/* welding message strings */
LOCAL CHAR
* idle_msg = "IDLE", *welding_msg = "WELDING", *off_msg = "SHUTDOWN", *pos_msg = "POSITIONING", *complete_msg = "WELDING COMPLETE", *place_msg = "IN PLACE", *none_msg = "NONE", *move1_msg = "MOVE TO CELL 2", *move2_msg = "MOVE TO ACCUMULATOR", *load1_msg = "LOAD FROM STAMPING", *load2_msg = "LOAD FROM CELL 1", *online_msg = "ON-LINE";
/* stamping message strings */
LOCAL CHAR
* off_man_msg = "OFF - MANUAL", *off_auto_msg = " OFF - AUTO ", *on_man_msg = " ON - MANUAL", *on_auto_msg = " ON - AUTO ";
void UpdateModel
V_P_ ((void))
{
INT i;
/* -------------------------------------------------------------------- */
/* Update the STAMPING AREA */
/* -------------------------------------------------------------------- */
/* Update Stamping Pressure */
for (i = 0; i < NUM_STAMPERS; i++)
{
if (!stamping_on[i])
stamping_pressure[i] = 5;
else if (stamping_up[i])
stamping_pressure[i] = 35;
else
stamping_pressure[i] = 65;
}
/* Update Stamping Positions and Graphs */
elapsed_time = TIME - current_time;
if (elapsed_time >= STAMPING_UPDATE_TIME)
{
for (i = 0; i < NUM_STAMPERS; i++)
{
if (ActiveDrawport == DrawportId[STAMPING_VIEW] ||
ActiveDrawport == DrawportId[STAMPING_VIEW + 1 + i])
{
if (stamping_on[i] && stamping_auto[i])
{
stamping_up[i] = DOWN;
(VOID) TdpDrawNext (ActiveDrawport);
stamping_up[i] = UP;
(VOID) TdpDrawNext (ActiveDrawport);
if (stamping_temp[i] < UPPER_TEMP)
stamping_temp[i] += temp_factor[i];
}
else if (stamping_temp[i] > LOWER_TEMP)
stamping_temp[i] -= temp_factor[i];
}
}
/* update the counters based on the update timer */
if ((welding_on[0] || welding_on[1]) && accum_pcs < 20)
++accum_pcs;
else if (!welding_on[0] && !welding_on[1] && accum_pcs > 0)
--accum_pcs;
total_pcs = accum_pcs + welding_on[0] + welding_on[1] + 3;
for (i = 0; i < NUM_STAMPERS; i++)
total_pcs = stamping_on[i];
current_time = TIME;
}
for (i = 0; i < NUM_STAMPERS; i++)
{
if (!stamping_on[i] && !stamping_auto[i])
(VOID) S_STRCPY (&stamping_status[i][0], off_man_msg);
else if (!stamping_on[i] && stamping_auto[i])
(VOID) S_STRCPY (&stamping_status[i][0], off_auto_msg);
else if (stamping_on[i] && !stamping_auto[i])
(VOID) S_STRCPY (&stamping_status[i][0], on_man_msg);
else if (stamping_on[i] && stamping_auto[i])
(VOID) S_STRCPY (&stamping_status[i][0], on_auto_msg);
}
/* -------------------------------------------------------------------- */
/* Update the WELDING AREA */
/* -------------------------------------------------------------------- */
cycle_timer = TIME - current_cycle_time;
if (cycle_timer >= CYCLE_LENGTH)
{
for (i = 0; i < NUM_WELDERS; i++)
{
current_cycle_counter = (INT) welding_cycle[i];
if (ActiveDrawport == DrawportId[WELDING1_VIEW + i])
if (welding_on[i])
{
/* Update the cycle counter */
current_cycle_counter++;
if (current_cycle_counter > NUM_OF_STEPS)
current_cycle_counter = 1;
/* Update the welding status strings */
if (current_cycle_counter == WELDING_STEP)
(VOID) S_STRCPY (&welding_status[i][0], welding_msg);
else
(VOID) S_STRCPY (&welding_status[i][0], idle_msg);
/* Update the welding piece status */
switch (current_cycle_counter)
{
case 1:
welding_unit_id[i]++;
if (i == 0)
(VOID) S_STRCPY (&welding_pcs_status[i][0], load1_msg);
else
(VOID) S_STRCPY (&welding_pcs_status[i][0], load2_msg);
break;
case 2:
(VOID) S_STRCPY (&welding_pcs_status[i][0], pos_msg);
break;
case 3:
(VOID) S_STRCPY (&welding_pcs_status[i][0], place_msg);
break;
case 4:
break;
case 5:
(VOID) S_STRCPY (&welding_pcs_status[i][0], complete_msg);
break;
case 6:
if (i == 0)
(VOID) S_STRCPY (&welding_pcs_status[i][0], move1_msg);
else
(VOID) S_STRCPY (&welding_pcs_status[i][0], move2_msg);
break;
} /* end of switch statement */
/* Update the Welding Temp */
if (welding_temp[i] < WELD_TEMP_MAX)
welding_temp[i] += 3;
}
else
{ /* Welder isn't on, reset */
(VOID) S_STRCPY (&welding_status[i][0], off_msg);
(VOID) S_STRCPY (&welding_pcs_status[i][0], none_msg);
current_cycle_counter = 0;
if (welding_temp[i] > WELD_TEMP_MIN)
welding_temp[i] -= 3;
}
welding_cycle[i] = (FLOAT) current_cycle_counter;
}
current_cycle_time = TIME;
} /* end of cycle timer update */
/* update the indicator lights on the welding screens */
for (i = 0; i < NUM_WELDERS; i++)
{
current_cycle_counter = (INT) welding_cycle[i];
if (welding_on[i])
(VOID) S_STRCPY (&welding_status[i][0], online_msg);
else
(VOID) S_STRCPY (&welding_status[i][0], off_msg);
if (welding_on[i] && current_cycle_counter == WELDING_STEP)
{
welding_curr[i] = 275;
welding_green_on[i] = ON;
welding_yellow_on[i] = OFF;
welding_red_on[i] = OFF;
}
else if (welding_on[i] && current_cycle_counter != WELDING_STEP)
{
welding_curr[i] = 50;
welding_green_on[i] = OFF;
welding_yellow_on[i] = ON;
welding_red_on[i] = OFF;
}
else if (!welding_on[i])
{
welding_curr[i] = 0;
welding_green_on[i] = OFF;
welding_yellow_on[i] = OFF;
welding_red_on[i] = ON;
}
}
/* -------------------------------------------------------------------- */
/* Update the PAINT SHOP AREA */
/* -------------------------------------------------------------------- */
if (ActiveDrawport == DrawportId[PAINT_SHOP_VIEW])
{
for (i = 0; i < NUM_OVENS; i++)
{
/* determine oven temperature */
if (oven_auto[i])
{
oven_delta[i] = (oven_set[i] - oven_temp[i]) / OVEN_FACTOR;
if (oven_temp[i] < MAX_OVEN_TEMP && oven_temp[i] > 0)
oven_temp[i] = (oven_temp[i] + oven_delta[i]);
if (DV_VIABS (oven_set[i] - oven_temp[i]) < 1)
oven_temp[i] = oven_set[i];
}
/* check oven temperature alarms */
if (oven_temp[i] != oven_prev_temp[i])
{
/* we've changed alarm status, reset the acknowledge flag */
if ((oven_prev_temp[i] <= CAUTION_OVEN_TEMP &&
oven_temp[i] > CAUTION_OVEN_TEMP) ||
(oven_prev_temp[i] > CAUTION_OVEN_TEMP &&
oven_temp[i] <= CAUTION_OVEN_TEMP) ||
(oven_prev_temp[i] <= ALARM_OVEN_TEMP &&
oven_temp[i] > ALARM_OVEN_TEMP) ||
(oven_prev_temp[i] > ALARM_OVEN_TEMP &&
oven_temp[i] <= ALARM_OVEN_TEMP))
oven_ack[i] = 0;
oven_prev_temp[i] = oven_temp[i];
}
/* Update the blinking */
if (oven_ack[i])
oven_blink[i] = 1;
else
{
oven_counter[i]++;
if (oven_counter[i] >= OVEN_BLINK_RATE)
{
oven_counter[i] = 0;
oven_blink[i] = (oven_blink[i]) ? (FLOAT)0 : (FLOAT)1;
}
}
}
}
} /* END UPDATE MODEL FUNCTION */
/* -------------------------------------------------------------------
|
| RaiseOrLowerStamper
| Function to control stampers when they are in manual mode.
*/
void
RaiseOrLowerStamper (position, machine_id)
int position;
int machine_id;
{
INT machine_index;
machine_index = machine_id - 1;
if (!stamping_auto[machine_index])
{
if (position == LOWER_STAMPER_COMMAND)
stamping_up[machine_index] = DOWN;
else
stamping_up[machine_index] = UP;
}
}
/* -------------------------------------------------------------------
|
| IncOrDecOven
| Function to control ovens when the are in manual mode.
*/
void
IncOrDecOven (direction, oven_id)
int direction;
int oven_id;
{
INT oven_index;
oven_index = oven_id - 1;
if (!oven_auto[oven_index])
{
if (direction == INC_OVEN_COMMAND)
{
oven_output[oven_index] += 5;
if (oven_output[oven_index] > 100)
oven_output[oven_index] = 100;
}
else
{
oven_output[oven_index] -= 5;
if (oven_output[oven_index] < 0)
oven_output[oven_index] = 0;
}
/* Set the oven temperature */
oven_temp[oven_index] = oven_output[oven_index] * 6;
}
}
/* -------------------------------------------------------------------
|
| AckOvenAlarm
| Function to acknowledg oven temperature alarms.
*/
void
AckOvenAlarm (oven_id)
int oven_id;
{
INT oven_index;
/* Only acknoledge the alarm if an alarm is occuring */
oven_index = oven_id - 1;
if (oven_temp[oven_index] > CAUTION_OVEN_TEMP)
oven_ack[oven_index] = 1;
}